package com.hpe.mapper;

import com.hpe.entity.Book;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface BookMapper {
    //查询全部图书信息
    @Select("SELECT id,serial_number,name,author,publishing FROM bms_books")
    List<Book> selectAll();

    //搜索图书
    @Select("SELECT id,serial_number,name,author,publishing FROM bms_books WHERE serial_number LIKE #{serial_number} OR name LIKE #{name} OR author LIKE #{author}")
    List<Book> searchBook(Map<String,Object> params);

    //添加图书
    @Insert("INSERT INTO bms_books(serial_number,name,author,publishing) VALUES(#{serialNumber},#{name},#{author},#{publishing})")
    void insertBook(Book book);

    //查询图书编号
    @Select("SELECT serial_number FROM bms_books WHERE serial_number=#{serial_number}")
    String selectSerialNumber(String serialNumber);

    //修改图书
    @Update("UPDATE bms_books SET name=#{name},author=#{author},publishing=#{publishing} WHERE serial_number=#{serial_number}")
    void updateBook(Map<String,Object> params);

    //删除图书
    @Delete("DELETE FROM bms_books WHERE serial_number=#{serial_number}")
    void deleteBook(String serialNumber);
}
